<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>View Credit Account | Merlion's ERP System</title>
    </ui:define>
    
    
    <ui:define name="content">
        <f:view beforePhase="#{viewCashInAdvanceManagerBean.initView}">
            
            <h:form prependId="false">
            <p:panel id="panel" header="Add Cash In Advance for Customer"> 
                <p:ajaxStatus style="width:16px;height:16px;">   
                    <f:facet name="start">   
                        <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                    </f:facet> 
 
                    <f:facet name="complete">   
                        <h:outputText value="" />   
                    </f:facet>   
                </p:ajaxStatus> 
 
                <p:messages /> 
 
                <h:panelGrid columns="3" cellpadding="10"> 
                    <h:outputLabel for="customerName" style="font-weight: bold" value="Company Name: " /> 
                    <p:autoComplete value="#{viewCashInAdvanceManagerBean.saleLeadName}" required="true"
                                    id="customerName" label="customerName" requiredMessage="Company Name is required." completeMethod="#{viewCashInAdvanceManagerBean.complete}">
                        <p:ajax update="panel" listener="#{viewCashInAdvanceManagerBean.retrieve}"/>
                    </p:autoComplete>
                        <p:message for="customerName" /> 
                    
                    <p:commandButton value="Retrieve" actionListener="#{viewCashInAdvanceManagerBean.retrieve}" update="panel"/>
                    
                    <h:outputLabel for="registrationNumber" style="font-weight: bold" value="Registration Number: " /> 
                    <h:outputText id="registrationNumber" value="#{viewCashInAdvanceManagerBean.selectedCustomer.registrationNumber}"> 
                    </h:outputText> 
                    <p:message for="registrationNumber" /> 
 
                    <h:outputLabel for="creditAccountId" style="font-weight: bold" value="Credit Account ID: " /> 
                    <h:outputText id="creditAccountId" value="#{viewCashInAdvanceManagerBean.selectedCustomer.creditAccount.creditAccountId}">                         
                    </h:outputText> 
                    <p:message for="creditAccountId" /> 
                    
                    <h:outputLabel for="deposit" style="font-weight: bold" value="Deposit ($): " /> 
                    <h:outputText id="deposit" value="#{viewCashInAdvanceManagerBean.selectedCustomer.creditAccount.deposit}">                         
                    </h:outputText> 
                    <p:message for="deposit" /> 
                    
                    <h:outputLabel for="creditLimit" style="font-weight: bold" value="Credit Limit: " /> 
                    <h:outputText id="creditLimit" value="#{viewCashInAdvanceManagerBean.selectedCustomer.creditAccount.creditLimit}">                         
                    </h:outputText> 
                    <p:message for="creditLimit" />
                    
                    <h:outputLabel for="creditBalance" style="font-weight: bold" value="Credit Balance: " /> 
                    <h:outputText id="creditBalance" value="#{viewCashInAdvanceManagerBean.selectedCustomer.creditAccount.creditBalance}">                         
                    </h:outputText> 
                    <p:message for="creditBalance" />
                    </h:panelGrid>
                    
                <p:dataTable var="saleOrder" value="#{viewCashInAdvanceManagerBean.selectedCustomer.saleOrdersWithCIA}"
                         selection="#{viewCashInAdvanceManagerBean.selectedSaleOrder}" dynamic="true" paginator="true" rows="3" emptyMessage="No sale order"> 
          
                <p:column selectionMode="single" />
                    
                <f:facet name="header">
                        <h:outputText value="List of Sale Orders with Cash in Advance"/>
                    </f:facet>
                
                <p:column sortBy="#{saleOrder.id}" filterBy="#{saleOrder.id}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Sale Order" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.id}" /> 
                </p:column> 
                
                <p:column sortBy="#{saleOrder.totalPrice}" filterBy="#{saleOrder.totalPrice}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Price" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.totalPrice}" /> 
                </p:column> 
                
                

                <p:column sortBy="#{saleOrder.customer.saleLeadName}" filterBy="#{saleOrder.customer.saleLeadName}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Company" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.customer.saleLeadName}" /> 
                </p:column>

                
                
                <p:column sortBy="#{saleOrder.cashInAdvance.cashInAdvanceAmount}" filterBy="#{saleOrder.cashInAdvance.cashInAdvanceAmount}"> 
                    <f:facet name="header"> 
                        <h:outputText value="Amount of Cash" /> 
                    </f:facet> 
                    <h:outputText value="#{saleOrder.cashInAdvance.cashInAdvanceAmount}" /> 
                </p:column> 
                <f:facet name="footer">                   
                    <p:commandButton value="View full details" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="saleOrderViewDialog.show()"/>                        
                    </f:facet>                                
            </p:dataTable>
                    
                <p:dialog header="Sale Order Detail" widgetVar="saleOrderViewDialog" width="600" height="400" resizable="true" showEffect="clip" hideEffect="fold">
                <h:panelGrid id="display1" columns="2" cellpadding="4">
                    
                    <h:outputText value="Sale Order ID:"/>
                    <h:outputText value="#{viewCashInAdvanceManagerBean.selectedSaleOrder.id}"/>
                    
                    <h:outputText value="Date:"/>
                    <h:outputText value="#{viewCashInAdvanceManagerBean.selectedSaleOrder.saleOrderDate}"/>
                    
                    <h:outputText value="Company Name:"/>
                    <h:outputText value="#{viewCashInAdvanceManagerBean.selectedSaleOrder.customer.saleLeadName}"/>
                    
                    <h:outputText value="Credit Balance:"/>
                    <h:outputText value="#{viewCashInAdvanceManagerBean.selectedCustomer.creditAccount.creditBalance}"/>
                    
                    <h:outputText value="Credit Limit:"/>
                    <h:outputText value="#{viewCashInAdvanceManagerBean.selectedCustomer.creditAccount.creditLimit}"/>
                    
                    <h:outputText value="Total Cash In Advance:"/>
                    <h:outputText value="#{viewCashInAdvanceManagerBean.selectedSaleOrder.cashInAdvance.cashInAdvanceAmount}"/>
                    
                    
                </h:panelGrid>
                
                <p:dataTable var="lineItem" value="#{viewCashInAdvanceManagerBean.selectedSaleOrder.lineItems}"
                             dynamic="true" paginator="true" emptyMessage="No Product Type" id="display2">
                    <f:facet name="header">
                        <h:outputText value="Sale Order Information"/>
                    </f:facet>
                    <p:column sortBy="#{lineItem.product.productType}">
                        <f:facet name="header">
                            <h:outputText value="Type"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.product.productType}"/>
                    </p:column>
                        
                    <p:column sortBy="#{lineItem.lineItemQuantity}">
                        <f:facet name="header">
                            <h:outputText value="Quantity"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.lineItemQuantity}"/>
                    </p:column>
                    
                    <p:column sortBy="#{lineItem.product.productPrice}">
                        <f:facet name="header">
                            <h:outputText value="Price per unit"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.product.productPrice}"/>
                    </p:column>
                    
                    <p:column sortBy="#{lineItem.volumeDiscountRate}">
                        <f:facet name="header">
                            <h:outputText value="Volume Discount(%)"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.volumeDiscountRate}"/>
                    </p:column>
                    
                    <p:column sortBy="#{lineItem.finalPrice}">
                        <f:facet name="header">
                            <h:outputText value="Price"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.finalPrice}"/>
                    </p:column>
                    
                    <f:facet name="footer">
                        <h:outputText value="Total Price: "/>
                        <h:outputText value="#{viewCashInAdvanceManagerBean.selectedSaleOrder.totalPrice}"/>                        
                    </f:facet>
                 </p:dataTable>
                    
                    
            </p:dialog>
                
                </p:panel> 
        </h:form>
        </f:view>
        
    </ui:define>

</ui:composition>
